package com.vecspace.data.numerical;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;

public abstract class HNumericalJsonDeserializer<T> extends JsonDeserializer<T>{

	protected void deserialize(HNumerical numerical, JsonParser p, DeserializationContext ctxt)
			throws IOException, JsonProcessingException {
		JsonNode node = p.getCodec().readTree(p);
		String text = null;
		if(node.isValueNode()) {//直接获取数值
			text = node.asText();
			
		}else {
			JsonNode valueNode = node.get("value");
			if(valueNode != null) {
				text = valueNode.asText();				
			}
		}
		numerical.setText(text);//保证对数值进行单位转换
	}

}
